package services;

import java.io.File;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import play.libs.Codec;
import utils.BizConstants;
import utils.UUIDString;
import vos.HraDetailView;
import vos.SjbbSearchVo;

import com.aton.db.SessionFactory;

import models.User;
import models.WebHraDetail;
import models.mappers.UserMapper;
import models.mappers.WebHraDetailMapper;

public class WebHraDetailService{
	private static final Logger log = LoggerFactory.getLogger(User.class);
	/**
	 * 保存webHRA数据
	 *
	 * @Title: insertHRAData 
	 * @param webHra HRA设备检测数据
	 * @return: void
	 */
	public static void insertHRAData(WebHraDetail webHra){
		Date date=new Date();
		webHra.createtime=date;
		SqlSession ss = SessionFactory.getSqlSessionWithoutAutoCommit();
		try{
			WebHraDetailMapper mapper = ss.getMapper(WebHraDetailMapper.class);
			webHra.did=UUIDString.create();
			mapper.insert(webHra);
			ss.commit();
		}catch(Exception e){
			ss.rollback();
			e.printStackTrace();
			log.warn("体检数据保存失败 id为"+webHra.idcard);
		}
		finally {
            ss.close();
        }
	}
	/**
	 * 根据身份证和日期查看当前日期的检查序号
	 *
	 * @Title: getUserPdf 
	 * @param pdfname
	 * @param nowdate 
	 * @param endDate 
	 * @return
	 * @return: String
	 */
	public static Long getUserPdf(String idcard, String dateString) {
		// TODO Auto-generated method stub
		SqlSession ss = SessionFactory.getSqlSession();
		try{
			WebHraDetailMapper mapper = ss.getMapper(WebHraDetailMapper.class);
			Map<String,String> map=new HashMap<String,String>();
			map.put("idcard", idcard);
			map.put("dateString", dateString);
			return mapper.getUserPdf(map);
		}catch(Exception e){
			e.printStackTrace();
		}
		finally {
            ss.close();
        }
		return null;
	}
}
